package com.core.reach.snowflakeactive.controller;

import com.core.reach.snowflakeactive.service.IdGeneratorService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author ga.zhang
 * @version V1.0
 * @description: TODO
 * @date 2020/4/2 11:39
 **/
@RestController
public class IdGeneratorController {

    @Resource
    private IdGeneratorService idGeneratorService;

    @GetMapping("/get")
    public String snowFlakeId() {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        for (int i = 1; i <= 20; i++) {
            executorService.submit(() -> {
                System.out.println(idGeneratorService.snowFlakeId());
            });
        }
        executorService.shutdown();
        return "雪花算法生成id成功";
    }

}
